package org.rcloud.io.service.impl;


import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.DouyinMapper;
import org.rcloud.io.model.Douyin;
import org.rcloud.io.service.DouyinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DouYinServiceImpl implements DouyinService {

    @Autowired
    private DouyinMapper dm;


    @Override
    public PageVo<Douyin> findDouyin() {

        try {
            List<Douyin> list = dm.findAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }


    }

    @Override
    public ResultVo findByEid(String eid) {

        if (eid.equals("") || eid == null){
            return ResultVo.setError("eid为空");
        } else {
            try {
                Douyin douyin = dm.findByEid(eid);
                return ResultVo.setOK(douyin);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo saveDouyin(Douyin douyin) {

        if (douyin.equals("") || douyin == null){
            return ResultVo.setError("添加数据为空");
        } else {
            dm.insert(douyin);
            return ResultVo.setOK(null);
        }

    }

    @Override
    public ResultVo updateDouyin(Douyin douyin) {

        if (douyin.equals("") || douyin == null){
            return ResultVo.setError("修改数据为空");
        } else {
            dm.updateByPrimaryKeySelective(douyin);
            return ResultVo.setOK(null);
        }

    }

    @Override
    public ResultVo findById(int id) {

        try {
            Douyin douyin = dm.selectByPrimaryKey(id);
            return ResultVo.setOK(douyin);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }
}
